package com.geek.factory.config;

import com.geek.factory.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author chenmin
 * @desc TODO
 * @date 2025/6/10
 *
 * 方式一：implements WebMvcConfigurer接口 + 重写相关方法
 * 方式二：@Configuration + @Bean 替换底层组件 ， 若替换的是WebMVC相关的则需要WebMvcConfigurer，以及重写相关方法
 */
//@Configuration
//public class WebConfig {
//
//    @Bean
//    public WebMvcConfigurer webMvcConfigurer(){
//        return new WebMvcConfigurer() {
//            //本地路径映射服务器
//            @Override
//            public void addResourceHandlers(ResourceHandlerRegistry registry) {
//                registry.addResourceHandler("/pic/**").addResourceLocations("file:\\D:\\Java\\temp1\\");
//            }
//
//            //添加拦截器
//            @Override
//            public void addInterceptors(InterceptorRegistry registry) {
//                registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**").excludePathPatterns("/login" , "/pic/**");
//            }
//        };
//    }
//
//    /*@Bean
//    public MultipartResolver multipartResolver(){
//        return null;
//    }*/
//}
/***************************************************/
//@Configuration(proxyBeanMethods = false)
//public class WebConfig {
//
//    @Bean
//    public WebMvcConfigurer webMvcConfigurer(){
//        return new WebMvcConfigurer() {
//            @Override
//            public void addInterceptors(InterceptorRegistry registry) {
//                registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**").excludePathPatterns("/login","/file/upload","/file/delete","loginByPhone");
//            }
//        };
//    }
//
//}
//@Configuration(proxyBeanMethods = false)
public class WebConfig {

//    @Bean
    public WebMvcConfigurer webMvcConfigurer(){
        return new WebMvcConfigurer() {
            @Override
            public void addInterceptors(InterceptorRegistry registry) {
                registry.addInterceptor(new LoginInterceptor())
                        .addPathPatterns("/**")
                        .excludePathPatterns(
                                "/auth/**",
                                "/login",
                                "/loginByPhone",
                                "/file/upload",
                                "/file/delete",
                                "/swagger-resources/**",
                                "/v2/api-docs",
                                "/webjars/**",
                                "/swagger-ui.html",
                                "/sms/**",
                                "/api/ams/**",
                                "/t_contract/**",
                                "/orders/**",
                                "/purchase-order/**",
                                "/stock-check/**"
                        );
            }
        };
    }

    /**
     * 配置RestTemplate用于HTTP请求
     */
    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}
